package com.dxj.dog.processadoption.controller;

import com.dxj.common.annotation.Log;
import com.dxj.common.core.controller.BaseController;
import com.dxj.common.core.domain.AjaxResult;
import com.dxj.common.core.page.TableDataInfo;
import com.dxj.common.enums.BusinessType;
import com.dxj.common.utils.poi.ExcelUtil;

import com.dxj.dog.processadoption.domain.DogAdoptionProcess;
import com.dxj.dog.processadoption.service.IDogAdoptionProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 领养过程Controller
 *
 * @author 王清江
 * @date 2022-03-27
 */
@RestController
@RequestMapping("/system/adoptionprocess")
public class DogAdoptionProcessController extends BaseController {
    @Autowired
    private IDogAdoptionProcessService dogAdoptionProcessService;

    /**
     * 查询领养过程列表
     */
    @PreAuthorize("@ss.hasPermi('system:adoptionprocess:list')")
    @GetMapping("/list")
    public TableDataInfo list(DogAdoptionProcess dogAdoptionProcess) {
        startPage();
        List<DogAdoptionProcess> list = dogAdoptionProcessService.selectDogAdoptionProcessList(dogAdoptionProcess);
        return getDataTable(list);
    }

    /**
     * 导出领养过程列表
     */
    @PreAuthorize("@ss.hasPermi('system:adoptionprocess:export')")
    @Log(title = "领养过程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DogAdoptionProcess dogAdoptionProcess) {
        List<DogAdoptionProcess> list = dogAdoptionProcessService.selectDogAdoptionProcessList(dogAdoptionProcess);
        ExcelUtil<DogAdoptionProcess> util = new ExcelUtil<DogAdoptionProcess>(DogAdoptionProcess.class);
        util.exportExcel(response, list, "领养过程数据");
    }

    /**
     * 获取领养过程详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:adoptionprocess:query')")
    @GetMapping(value = "/{adoptionId}")
    public AjaxResult getInfo(@PathVariable("adoptionId") Long adoptionId) {
        return AjaxResult.success(dogAdoptionProcessService.selectDogAdoptionProcessByAdoptionId(adoptionId));
    }

    /**
     * 新增领养过程
     */
    @PreAuthorize("@ss.hasPermi('system:adoptionprocess:add')")
    @Log(title = "领养过程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DogAdoptionProcess dogAdoptionProcess) {
        return toAjax(dogAdoptionProcessService.insertDogAdoptionProcess(dogAdoptionProcess));
    }

    /**
     * 修改领养过程
     */
    @PreAuthorize("@ss.hasPermi('system:adoptionprocess:edit')")
    @Log(title = "领养过程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DogAdoptionProcess dogAdoptionProcess) {
        return toAjax(dogAdoptionProcessService.updateDogAdoptionProcess(dogAdoptionProcess));
    }


    /**
     * 确认收货
     */
    @PreAuthorize("@ss.hasPermi('dog:my:ok')")
    @Log(title = "确认收货", businessType = BusinessType.UPDATE)
    @PutMapping("/getDog")
    public AjaxResult getDog(@RequestBody DogAdoptionProcess dogAdoptionProcess) {
        return toAjax(dogAdoptionProcessService.updateDogAdoptionProcess(dogAdoptionProcess));
    }

    /**
     * 删除领养过程
     */
    @PreAuthorize("@ss.hasPermi('system:adoptionprocess:remove')")
    @Log(title = "领养过程", businessType = BusinessType.DELETE)
    @DeleteMapping("/{adoptionIds}")
    public AjaxResult remove(@PathVariable Long[] adoptionIds) {
        return toAjax(dogAdoptionProcessService.deleteDogAdoptionProcessByAdoptionIds(adoptionIds));
    }
}
